﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace XrmLibrary.MsCrm4Adapter.Extensions
{
    public static class OrderExpressionExtensions
    {
        public static Microsoft.Crm.Sdk.Query.OrderExpression ToCrm4OrderExpression(this Microsoft.Xrm.Sdk.Query.OrderExpression crm2011OrderExpression)
        {
            Microsoft.Crm.Sdk.Query.OrderExpression crm4OrderExpression =
                new Microsoft.Crm.Sdk.Query.OrderExpression()
                {
                    AttributeName = crm2011OrderExpression.AttributeName,
                    OrderType = crm2011OrderExpression.OrderType.ToCrm4OrderType()
                };

            return crm4OrderExpression;
        }

        public static Microsoft.Xrm.Sdk.Query.OrderExpression ToCrm2011OrderExpression(this Microsoft.Crm.Sdk.Query.OrderExpression crm4OrderExpression)
        {
            Microsoft.Xrm.Sdk.Query.OrderExpression crm2011OrderExpression =
                new Microsoft.Xrm.Sdk.Query.OrderExpression()
                {
                    AttributeName = crm4OrderExpression.AttributeName,
                    OrderType = crm4OrderExpression.OrderType.ToCrm2011OrderType()
                };

            return crm2011OrderExpression;
        }

        public static IEnumerable<Microsoft.Xrm.Sdk.Query.OrderExpression> ToCrm2011OrderExpressionCollection(this ArrayList crm4OrderExpression)
        {
            foreach (Microsoft.Crm.Sdk.Query.OrderExpression orderExpression in crm4OrderExpression)
            {
                yield return orderExpression.ToCrm2011OrderExpression();
            }
        }
    }
}
